package com.example.smartcity.ui.home

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.example.smartcity.logic.Repository
import com.example.smartcity.logic.model.Login
import com.example.smartcity.logic.model.More
import com.example.smartcity.logic.model.NewSEntity
import com.example.smartcity.logic.model.Slideshow
import okhttp3.RequestBody

class HomeViewModel : ViewModel() {

    /**
     * TODO viewModel 轮播图
     */
    private val slideshowData = MutableLiveData<Map<String, Int>>()

    val placeList = ArrayList<Slideshow.Rows>()

    val placeLiveData = Transformations.switchMap(slideshowData){ query ->
        Repository.getSlideshow(query)
    }

    fun slideshow(map: Map<String, Int>){
        slideshowData.value = map
    }



    /**
     * TODO viewModel 全部服务
     */
    private val moreData = MutableLiveData<String>()

    val moreList = ArrayList<More.Rows>()

    val moreLiveData = Transformations.switchMap(moreData){query ->
        Repository.getMore(query)
    }

    fun more(type: String){
        moreData.value = type
    }


    /**
     * TODO viewModel 热门主题
     */
    private val hotData = MutableLiveData<String>()

    val hotList = ArrayList<NewSEntity.Rows>()

    val hotLiveData = Transformations.switchMap(hotData){ query ->
        Repository.getNewS(query)
    }

    fun hot(test: String){
        hotData.value = test
    }


    /**
     * 新闻
     */
    private val newSData = MutableLiveData<Int>()
    val newSList = ArrayList<NewSEntity.Rows>()
    val newSLiveData = Transformations.switchMap(newSData){query ->
        Repository.getNewSEntityType(query)
    }
    fun newS(test: Int){
        newSData.value = test
    }


    /**
     * 获取全部新闻
     */
    private val newsDataAll = MutableLiveData<String>()
    val newsAll = ArrayList<NewSEntity.Rows>()
    val newSLiveDataAll = Transformations.switchMap(newsDataAll){
        Repository.getNewsAll()
    }
    fun newsAll(news: String){
        newsDataAll.value = news
    }

}